fix: regex simplification of anchored patterns produces wrong results#22727
Open
lyne7-sc wants to merge 5 commits into
Open
fix: regex simplification of anchored patterns produces wrong results#22727lyne7-sc wants to merge 5 commits into
lyne7-sc wants to merge 5 commits into
Conversation
Jefffrey
approved these changes
Jun 3, 2026
martin-g
reviewed
Jun 4, 2026
| Barrr | ||
|
|
||
| query T | ||
| SELECT * FROM test WHERE column1 ~* '^(barrr|bazzz)$' |
Member
There was a problem hiding this comment.
Tests with negation+regex are missing (!~ and !~*).
| Bazzz | ||
|
|
||
| statement ok | ||
| CREATE TABLE test_regex_utf8view(s VARCHAR) AS VALUES ('foo'), ('Bazzz'); |
Member
There was a problem hiding this comment.
Question to educate myself: How the values here are Utf8View ?
I'd expect some casting to achieve that.
| query T | ||
| SELECT * FROM test_regex_utf8view WHERE s ~* '^bazzz$' | ||
| ---- | ||
| Bazzz |
Member
There was a problem hiding this comment.
How this asserts the expected result ?
Neither the optimization nor the type is asserted.
Maybe use EXPLAIN ... and assert its output instead ?!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
The regex simplification rule rewrites anchored regex matches (
^literal$,^(a|b)$) into cheaper=/IN/LIKEexpressions. Two bugs in that path:Utf8vialit(...), so on aUtf8View/LargeUtf8column the rewritten comparison failed at execution withInvalid comparison operation: Utf8View == Utf8.~*(case-insensitive) anchored literal was rewritten to a case-sensitive=, silently dropping rows that differ only in case.What changes are included in this PR?
string_scalar.to_expr(...)so its type follows the column type (Utf8/LargeUtf8/Utf8View), consistent with the existingLIKEbranches.~*anchored literals toILIKEinstead of=. The existingis_safe_for_likeguard ensures the literal has no%/_, so this is an exact case-insensitive match. (Anchored alternations under~*still fall back to regex evaluation.)Are these changes tested?
Yes.
predicates.sltnow covers anchored~/~*, single literals and alternations, over bothUtf8andUtf8Viewcolumns. Existingregex.rsunit tests still pass.Are there any user-facing changes?
Yes, bug fixes only